import random;

dx = [0, 0, -1, 1];
dy = [1, -1, 0, 0];

def check(a, n, m, x, y):
	if (a[x][y] > 0): return False;
	for k in range(4):
		if x + dx[k] >= 0 and x + dx[k] < n \
		and y + dy[k] >= 0 and y + dy[k] < m:
			if a[x + dx[k]][y + dy[k]] > 0:
				return False;
	return True;
	
r = random;
T = 30;
print(T);
for test in range(T):
	n = r.randint(10, 100);
	m = r.randint(10, 100);
	a = [[0 for y in range(m)] for y in range(n)];
	k = r.randint(1, 10);
	for j in range(n * m * k // 100):
		x = r.randint(0, n - 1);
		y = r.randint(0, m - 1);
		while (not check(a, n, m, x, y)):
			x = r.randint(0, n - 1);
			y = r.randint(0, m - 1);
		a[x][y] = r.randint(1, 50);
	print(str(n) + " " + str(m));
	for i in range(n):
		for j in range(m):
			print(a[i][j], end=" ");
		print();
	print();

			